package com.Controller.servlet;

import com.Model.Pojo.Users;
import com.Model.denglu.PanDuanZhangHao;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

public class DengLu extends HttpServlet {

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws IOException {

		response.setContentType("text/html");//设置参数传递编码方式
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");

		HttpSession session = request.getSession(false);//获取session
		String name = request.getParameter("userid"); //获取账号密码身份信息
		String pass = request.getParameter("passwordinput");
		String shenfen = request.getParameter("shenfen");
		String url = request.getParameter("url");

		//实例化判断账号密码的对象
		PanDuanZhangHao panduan = new PanDuanZhangHao(name, pass, shenfen);
		String flag = panduan.panDuan(); //第二次判断账号密码是否正确
		if(flag.equals("false")){
			response.sendRedirect(url); //返回之前的页面。
		}else{
			pass += "1";
			Users users = panduan.getUsersByNameOrShoujihaoOrYouxiang(flag,name,pass);
			//System.out.println(users.getZhanghao() + " " + users.getMima() + " " + users.getShoujihao() + " " + users.getYouxiang());
			session.setAttribute("users", users); //把user存在session里面
			response.sendRedirect(url); //返回之前的页面。
		}
	}
}
